﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using CustomsSystem.BLL;
using CustomsSystem.Model;

namespace WEB.Code
{
    public partial class AddCode : System.Web.UI.Page
    {
           DataSet ds=new DataSet();
           CodeManage BLL = new CodeManage();
           Info_code info_code = new Info_code();
           protected void Page_Load(object sender, EventArgs e)
           {
               if (!IsPostBack)
               {
                   if (Request.QueryString["type"] != "")
                   {
                       string codeID = Convert.ToString(Request.QueryString["type"]);
                       DropDownList1.SelectedValue = codeID;
                   }
               }
               //获取代码类别有多少个代码。
               ds = BLL.GetList(" codeType='".Trim() + DropDownList1.Text.Trim() + "'".Trim());
               int num = ds.Tables[0].Rows.Count + 1;//得到自动增加的编号数
               Label5.Text = Convert.ToString(num);
           }

           protected void Button1_Click(object sender, EventArgs e)
           {
               string checkType = DropDownList1.Text;
               bool a;
               a = BLL.Exists(checkType, Convert.ToInt32(Label5.Text));
               
               if (a == false)
               {
                   if (TextBox2.Text == "")
                   {
                       Response.Write("<Script>alert('请输入完整!')</script>");
                       return;
                   }
                   else
                   {
                       info_code.codeID =Convert.ToInt32( Label5.Text);
                       info_code.codeName = TextBox2.Text;
                       info_code.codeType = DropDownList1.Text;
                       BLL.Add(info_code);
                       Response.Write("<Script>alert('增加成功!')</script>");
                       TextBox2.Text = string.Empty;
                       return;
                   }
               }
               else
               {
                   Response.Write("<Script>alert('已有此代码，请重新输入!')</script>");
                   return;
               }
           }


           protected void Button2_Click(object sender, EventArgs e)
           {
               string codeID = Convert.ToString(Request.QueryString["type"]);
               Response.Redirect("codeIndex.aspx?AddType=" + codeID);
           }
    }
}